/*
 * JabberLogger
 * Created: Dec 27, 2006 
 * by abargnesi<mailto:abargnesi@aquent.com/>
 */
package com.den4.jynform.alerts;

import java.io.Serializable;

import org.jivesoftware.smack.GoogleTalkConnection;
import org.jivesoftware.smack.XMPPException;

public class GoogleTalkLogger implements Logger, Serializable {
    private GoogleTalkConnection gtCon;
    private String loginUser;
    private String loginPass;
    private String recipientUser;
    
    public String getLoginUser() {
        return loginUser;
    }
    
    public void setLoginUser(String loginUser) {
        this.loginUser = loginUser;
    }

    public String getLoginPass() {
        return loginPass;
    }
    
    public void setLoginPass(String loginPass) {
        this.loginPass = loginPass;
    }

    public String getRecipientUser() {
        return recipientUser;
    }
    
    public void setRecipientUser(String recipientUser) {
        this.recipientUser = recipientUser;
    }
    
    public void connect() {
        try {
            gtCon = new GoogleTalkConnection();
            gtCon.login(loginUser, loginPass);
        } catch (XMPPException e) {
            e.printStackTrace();
        }
    }
    
    public void disconnect() {
        gtCon.close();
    }
    
    public void log(String subject, String body) {
        //Jabber connect to google talk.
        if(!gtCon.isConnected()) {
            connect();
        }
        
        try {
            gtCon.createChat(recipientUser).sendMessage(body);
        } catch (XMPPException e) {
            e.printStackTrace();
            gtCon.close();
        }
    }
}
